<%@ page contentType="text/html;charset=UTF-8" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="shiro" uri="http://shiro.apache.org/tags" %>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %> 
<%@ taglib prefix="tags" tagdir="/WEB-INF/tags" %>
<c:set var="ctx" value="${pageContext.request.contextPath}"/>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
	<title>_处理线下订单</title>
	<script type="text/javascript">
	
	//页面初始
    $(function() {
       var status='${ulorder.status}';
       if(status=='login'){
       }else{
          $("#btn_send").remove();
       }
       
    });
	
	//创建订单
	function send(){
	   //验证信息
	   var weight=$("#_weight").val().trim();
	   if(isNaN(weight) || weight==''){
          alert("请录入正确格式重量信息！");
          return;
       }
	   
	   var expressNo=$("#_expressNo").val().trim();
	   if(expressNo==''){
	         alert("请填写快递单号");
	         return;
	   }
	   
	    var btn=$("#btn_send");
	    btn.attr("disabled",true);
	    btn.attr("class","btn");
	   
	   $.ajax({
			type : 'post',
			url : '${ctx}/ulorder/ajaxSend',
			data:{
			    weight:weight,
			    expressNo:expressNo,
				orderno:'${ulorder.orderno}'
			},
			dataType : 'json',
			success : function(data) {
			      if(data==true){
			          window.alert("发货成功！"); 
			          location.href='${ctx}/ulorder/v2_toUlorderHandleMgrPage';
			      }
			      if(data==false) {
			    	  window.alert("发货失败！");
			      }
			      btn.attr("disabled",false);
    		      btn.attr("class","btn btn-warning");
			    
			},
			error : function() {
				btn.attr("disabled",false);
	    		btn.attr("class","btn btn-warning");
				alert("网络繁忙，请稍后重试...");
			}
		});
	
	}
	
	//初始化打印机
	function InitializePrinter(){
		packFormPrinter("pickPickPrint");
	}
	
	//开始打印
	function toPrint(){
		$('myinfo').modal('hide');
		var printName = $("#pickPickPrint").val();
		var customerOrdeno ='${ulorder.customerOrdeno}';
		showBg();
		$.ajax({
			type : 'post',
			url : '${ctx}/ulorder/ajaxToPrint',
			data : {
				orderno:'${ulorder.orderno}',
				customerCode:'${ulorder.customerCode}'
			},
			dataType : 'json',
			success : function(data){
				if(data != "error"){
					tpPrintInfo(data,printName,customerOrdeno);
					closeBg();
				}else{
					alert("打印加载错误！");
					closeBg();
				}
			}
		});
	}
	function tpPrintInfo(taskItem,printName,customerOrdeno){
		var taskCode = taskItem[0].orderno;
		var str = '';
		var num = 0;
		LODOP.PRINT_INIT(taskCode);
		str +="<table width='100%' cellpadding='0' cellspacing='0' align = 'center' border='1'>";
		str +="<tr><td colspan= '7' align = 'center'><h3>拣货单(订单编号："+taskCode+")</h3>客户单号："+customerOrdeno+"</td></tr>";
		str +="<tbody align = 'center'><tr><td colspan= '2'>仓库</td><td colspan= '5'>"+taskItem[0].warehouseCode+"</td></tr>";
		str += "<tr style='font-size:10pt'><td width='7%'>序号</td><td width='10%'>商家</td><td width='18%'>库位</td><td width='18%'>箱位</td><td width='20%'>sku</td><td width='20%'>商品名</td><td width='7%'>数量</td></tr>";
		for(var i =0;i<taskItem.length;i++){
			str +="<tr style='font-size:12pt' ><td>"+(i+1)+"</td><td>"+taskItem[i].customerCode+"</td><td>"+taskItem[i].stockCode+"</td><td>"+taskItem[i].boxCode+"</td><td>"+taskItem[i].sku+"</td><td>"+taskItem[i].skuName+"</td><td>"+taskItem[i].num+"</td></tr>";
			num += taskItem[i].num;
		}
		str +="</tbody>";
		str +="<tfoot align = 'center'><tr><td colspan= '6'><h4>拣货单(订单编号："+taskCode+")</h4></td><td>"+num+"</td></tr></tfoot>";
		str +="</table>";
		LODOP.SET_PRINT_PAGESIZE(1, 0, 0,  $("#paperSizes").val()) ;
		LODOP.ADD_PRINT_TABLE(30,0, "100%","100%",str);
		if (LODOP.SET_PRINTER_INDEXA(printName)) {
			LODOP.PRINT(); 
		}
	}
    </script>
</head>

<body>
	<div id="fullbg"></div>
	<div id="dialog">
		<div>
			<img src="${ctx }/static/022.gif"></img>
		</div>
	</div>

	  <table id="contentTable" class="table  table-bordered table-condensed">
    <thead>
		<th style='vertical-align: middle;background-color: #6699CC;color: white;font-size: medium;' colspan="13" bgcolor="#8EB4CB">
		处理线下订单
		<a href="${ctx}/ulorder/exportExcel/${ulorder.orderno}"  role="button" class="btn btn-primary" style="margin-left:10px;" >导出拣货单</a>
		<input type="button" id="btn_send"  value="完成发货" class="btn btn-warning" style="margin-left:10px;" onclick="send();"/>
		<a href="#printPickInfo"  data-toggle="modal" role="button" class="btn btn-primary" onclick="InitializePrinter()">打印拣货单</a>
		</th>
	</thead>
		
  <tbody>
  <tr><td>

    <div class="tabbable">
    
	  	   <ul class="nav nav-tabs">
			   <li class="${tab1}"><a href="#tab1" data-toggle="tab">订单信息</a></li>
			   <li class="${tab2}"><a href="#tab2" data-toggle="tab">拣货信息</a></li>
		   </ul>
		
		   <div class="tab-content">
		   
		        <!-- 订单信息 -->
				<div class="tab-pane ${tab1}" id="tab1">
				  
				    <!-- 发货信息 -->
					<table class="table table-striped table-bordered table-condensed" style="margin-top: 0px;">
						<thead>
							<th style="vertical-align: middle; color: white; " colspan="6" bgcolor="#8EB4CB">发货信息 ：</th>
						</thead>
						<tr>
						   <td style="vertical-align: middle;width: 90px; text-align: center;">商家名称：</td>
						   <td style="width: 200px;">
						   <input  type="text"  value="${ulorder.customer.customerName}" class="input-medium"  style="margin-bottom:0px!important;"/>
						   </td>
						   
						   <td style="vertical-align: middle;width: 90px; text-align: center;">发货仓库：</td>
						   <td style="width: 200px;">
						      <input  type="text" value="${ulorder.warehouse.groupName}" class="input-medium"  style="margin-bottom:0px!important;"/> 
						   </td>
						   
						   <td style="vertical-align: middle;width: 90px; text-align: center;">重量（g）：</td>
						   <td>
						      <input  type="text" id="_weight" value="${ulorder.weight}" style="height: 15px!important;margin-bottom:0px!important;" />
						   </td>
					   </tr>
					   <tr>
						   <td style="vertical-align: middle;width: 90px; text-align: center;">快递公司：</td>
						   <td style="width: 200px;">
						     <input  type="text" value="${ulorder.company.companyName}" class="input-medium"  style="margin-bottom:0px!important;"/>
						   </td>
						   <td style="vertical-align: middle;width: 90px; text-align: center;" >快递单号：</td>
						   <td style="width: 200px;">
						      <input  type="text" id="_expressNo" value="${ulorder.expNo}" class="input-medium"  style="height: 15px!important;margin-bottom:0px!important;"/>
						   </td>
						   <td colspan="2"></td>
					   </tr>
					   
					   <tr>
						   <td style="vertical-align: middle;width: 90px; text-align: center;">备注信息：</td>
						   <td colspan="5">
						      <textarea id="_remark" style="width: 500px; height: 50px;" >${ulorder.remark}</textarea>
						   </td>
					   </tr>
					</table>
					
					<!-- 寄件信息 -->
					<table class="table table-striped table-bordered table-condensed" style="margin-top: 0px;">
						<thead>
							<th style="vertical-align: middle; color: white; " colspan="6" bgcolor="#8EB4CB">寄件信息：</th>
						</thead>
						<tr>
						   <td style="vertical-align: middle;width: 90px; text-align: center;">寄件人姓名：</td>
						   <td style="width: 200px;">
						       <input  type="text" id="_fromName" value="${ulorder.fromName}" class="input-medium"  style="height: 15px!important;margin-bottom:0px!important;"/>
						   </td>
						  <td style="vertical-align: middle;width: 90px; text-align: center;">联系人电话：</td>
						   <td style="width: 200px;">
						       <input  type="text" id="_fromTel" value="${ulorder.fromTel}" class="input-medium"  style="height: 15px!important;margin-bottom:0px!important;"/>
						   </td>
						   
						   <td style="vertical-align: middle;width: 90px; text-align: center;" >详细地址：</td>
						   <td>
						      <input  type="text" id="_fromAddress" value="${ulorder.fromAddress}"  style="height: 15px!important;margin-bottom:0px!important; width: 300px;"/>
						   </td>
					   </tr>
					</table>
					
					<!-- 收件信息 -->
					<table class="table table-striped table-bordered table-condensed" style="margin-top: 0px;">
						<thead>
							<th style="vertical-align: middle; color: white; " colspan="6" bgcolor="#8EB4CB">收件信息：</th>
						</thead>
						<tr>
						   <td style="vertical-align: middle;width: 90px; text-align: center;">收件人姓名：</td>
						   <td style="width: 200px;">
						       <input  type="text" id="_toName" value="${ulorder.toName}" class="input-medium"  style="height: 15px!important;margin-bottom:0px!important;"/>
						   </td>
						   
						    <td style="vertical-align: middle;  width: 90px; text-align: center;">联系人电话：</td>
						   <td style="width: 200px;">
						       <input  type="text" id="_toTel" value="${ulorder.toTel}" class="input-medium"  style="height: 15px!important;margin-bottom:0px!important;"/>
						   </td>
						   <td style="vertical-align: middle; width: 90px; text-align: center;" >详细地址：</td>
						   <td>
						      <input  type="text" id="_toAddress" value="${ulorder.toAddress}"  style="height: 15px!important;margin-bottom:0px!important; width: 300px;"/>
						   </td>
					   </tr>
					</table>
					
				</div>
				
				<!-- 商品信息-->
				<div class="tab-pane ${tab2}" id="tab2">
				
				<table id="contentTable" class="table  table-bordered table-condensed">
				    <thead>
						<th style="vertical-align: middle; color: white;" colspan="13" bgcolor="#8EB4CB">商品信息</th>
					</thead>
					<thead><tr>
					    <th>序号</th>
					    <th>sku</th>
					    <th>数量</th>
					</tr></thead>
					<c:if test="${empty goodsList or goodsList.size() eq 0}">
				       <tr id="nodata"><td colspan="6" height="50" style="vertical-align:middle; text-align: center;color: gray;font-size: 20px;">无已选商品</td></tr>
				    </c:if>
					<tbody >
					
					    <c:forEach items="${goodsList}" var="g" varStatus="i">
							<tr>
							   <td>${i.count}</td>
							   <td>${g.sku}</td>
							   <td>${g.qty}</td>
							</tr>
						</c:forEach>
					
					</tbody>
			    </table>
			    
			    <table id="contentTable" class="table  table-bordered table-condensed">
				    <thead>
						<th style="vertical-align: middle; color: white;" colspan="13" bgcolor="#8EB4CB">拣货信息</th>
					</thead>
					<thead><tr>
					    <th>序号</th>
					    <th>仓库</th>
					    <th>库位</th>
					    <th>箱位</th>
					    <th>sku</th>
					    <th>数量</th>
					</tr></thead>
					<c:if test="${empty pickInfoList or pickInfoList.size() eq 0}">
				       <tr id="nodata"><td colspan="6" height="50" style="vertical-align:middle; text-align: center;color: gray;font-size: 20px;">无已选商品</td></tr>
				    </c:if>
					<tbody >
					    <c:forEach items="${pickInfoList}" var="p" varStatus="i">
							<tr>
							   <td>${i.count}</td>
							   <td>${p.warehouseCode}</td>
							   <td>${p.stockCode}</td>
							   <td>${p.boxCode}</td>
							   <td>${p.sku}</td>
							   <td>${p.num}</td>
							</tr>
						</c:forEach>
					</tbody>
			    </table>
	         </div>
	         
	         
	     </div>
	 </div>
    
    </td></tr>
    </tbody>
  </table>

	<div class="modal  fade myinfo" tabindex="-1" role="dialog"
		aria-labelledby="myModalLabel" aria-hidden="true" id="printPickInfo">
		<div class="modal-dialog">
			<div class="modal-content">
				<div class="modal-header">
					<h3 id="myModalLabel">打印拣货单信息</h3>
					<span id="messageLable"></span>
				</div>
				<div class="modal-body" style="overflow: auto;">
					<div class="control-group">
						<div class="controls">
							选择打印机: <select id="pickPickPrint" name="packFormPrinter"
								style="width: 300px">

							</select>
						</div>
						<div class="controls">
							纸张的尺寸:
							<select id="paperSizes" name="paperSizes" class="form-control" style="width: 300px" >
											<option value="A4" selected="selected" >A4</option>
											<option value="A5" >A5</option>
							</select>
						</div>
					</div>
				</div>
				<div class="modal-footer">
					<a class="btn btn-primary" data-dismiss="modal" aria-hidden="true"
						onclick="toPrint()"> 立即打印 </a> <a class="btn"
						data-dismiss="modal" aria-hidden="true"> 关闭 </a>
				</div>
			</div>
		</div>
	</div>

</body>
</html>
